﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Permissions;
using System.Web.UI.WebControls.WebParts;
using SharePointOfView.Properties;

namespace SharePointOfView.WebControls
{
    [AttributeUsage(AttributeTargets.Property), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class LocalizedWebDescriptionAttribute : WebDescriptionAttribute
    {
        // Fields
        private string _description;
        public static new readonly WebDescriptionAttribute Default = new WebDescriptionAttribute();

        // Methods
        public LocalizedWebDescriptionAttribute()
            : this(string.Empty)
        {
        }

        public LocalizedWebDescriptionAttribute(string description)
        {
            this._description = Resources.ResourceManager.GetString(description);
        }

        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return true;
            }
            WebDescriptionAttribute attribute = obj as WebDescriptionAttribute;
            return ((attribute != null) && (attribute.Description == this.Description));
        }

        public override int GetHashCode()
        {
            return this.Description.GetHashCode();
        }

        public override bool IsDefaultAttribute()
        {
            return this.Equals(Default);
        }

        // Properties
        public override string Description
        {
            get
            {
                return this.DescriptionValue;
            }
        }

        protected new string DescriptionValue
        {
            get
            {
                return this._description;
            }
            set
            {
                this._description = value;
            }
        }

    }
}
